/**
 * 
 */
package info.niwota.home.fm;

import info.niwota.home.R;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * @author qiangli
 * 
 */
public class NewFileActivity extends ListActivity {

	private static final int[] items_res = new int[] { R.string.menu_newfolder,
			R.string.menu_newlink, R.string.menu_newtext,
			R.string.menu_newaudio, R.string.menu_newpicture,
			R.string.menu_newvideo, };
	private static final String[] items = new String[items_res.length];

	private static final String[] cmds = new String[] {
			BinConstant.BIN_NEWFOLDER, BinConstant.BIN_LINK,
			BinConstant.BIN_EDIT, BinConstant.BIN_RECORD,
			BinConstant.BIN_CAMERA, BinConstant.BIN_CAMCORDER };

	private ArrayAdapter<String> listAdapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTheme(android.R.style.Theme_Black_NoTitleBar);

		setContentView(R.layout.menu);
		
		TextView titleText = (TextView) findViewById(R.id.menu_title);
		Uri uri = getIntent().getData();
		
		titleText.setText(getString(R.string.title_newmenu, uri.getPath()));

		init();
	}

	private void init() {
		int len = items_res.length;
		for (int i = 0; i < len; i++) {
			items[i] = getString(items_res[i]);
		}
		listAdapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, items);
		setListAdapter(listAdapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		String item = listAdapter.getItem(position);
		for (int i = 0; i < items.length; i++) {
			if (item.equals(items[i])) {
				Intent data = new Intent();
				data.setAction(cmds[i]);
				setResult(RESULT_OK, data);
				finish();
			}
		}
	}
}
